(function($, doc, phone) {
	mui.init();
    var apage   = null;
	mui.plusReady(function() {
        var self    = plus.webview.currentWebview();
        // mui.preload({
        //     url: "chat_index.html",
        //     id: "chat_index.html",
        //     extras: {
        //         chatTitle: '555',
        //         chatHeader: '',
        //         roomId : 5
        //     }
        // });
		var settings = app.getSettings();
		var state = app.getState();
		var uid = state.user_id;

		var list = document.getElementById('list');
		var header = document.querySelector('header');
		//calc hieght
		list.style.height = (plus.display.resolutionHeight - 60) + 'px';
		//create
		window.indexedList = new mui.IndexedList(list);
		//var cdata = null;
		//console.log(cdata);
		var phones = sysphone.getFriendPin();
		document.querySelector("#list-area").innerHTML = template('list-template', {
			"flist": phones
		});
		//initheight();
		mui("#list-area").on("tap", "a", function() {
			var fid = this.getAttribute("fid");
			var head = this.getAttribute("head");
			var fname = this.getAttribute("title");
			var phone = this.getAttribute("phone");
			var cname = self.cname;
            //if(apage == null){
			apage = plus.webview.getWebviewById("chatbox");
            //}
            mui.fire(apage, 'SENDCARD', {fid : fid, head : head, fname : fname, phone : phone, cname:cname});
            //var targets = 'chat_index.html?chatTitle=' + fname + '&chatHeader=' + head + '&roomId=' + fid;
            plus.webview.currentWebview().close();
            //plus.webview.show('chatbox');
            
            mui.openWindow({
			 	url: 'chat_index.html',
			 	id: 'chatbox',
			 	extras: {
			 		chatTitle: plus.webview.currentWebview().chatTitle,
			 		chatHeader: plus.webview.currentWebview().chatHeader,
			 		roomId : plus.webview.currentWebview().roomId,
			 		roomType : plus.webview.currentWebview().roomType
			 	}
			 });
		});
	});
}(mui, document, window.phone));